<?php echo $this->render('/public/header'); ?>
<style>
    .jing-product {
        max-height: 100px;
        overflow: hidden;
    }

    .jing-product:hover {
        height: auto;
        max-height: none;
        overflow: auto;
    }

    [v-cloak] {
        display: none
    }
</style>
<script src="https://cdn.bootcss.com/element-ui/1.4.2/index.js"></script>
<link href="https://cdn.bootcss.com/element-ui/1.4.2/theme-default/index.css" rel="stylesheet">
<div class="col-xs-12" id="main" v-cloak>
    <div class="col-xs-6 col-lg-6 col-sm-6">
        <form class="form-inline">
            <select class="form-control" name="staff" v-model="staff">
                <option value=0>搜索业务员</option>
                <option v-for="staff in staff_list" :value="staff.job_number">{{staff.name}}</option>
            </select>
            <input type="text" v-model="pi" name="pi" placeholder="搜索pi编号" class="form-control"/>
            <button class="btn btn-success">搜索</button>
        </form>
    </div>
    <div style="float: right;margin-bottom: 10px;">
        <p><b>注意事项：</b></p>
        <p><b>一个客户的同几个产品（可能对数量，价格，或增加减少产品项目），都在同一个报价里面修改。</b></p>
        <p><b>一个客户先后对不同的产品进行报价，可以做在不同的报价单里。</b></p>
        <p><b>尽量在整个列表里面可以清楚看见自己对不同客户不同产品的历史报价</b></p>
    </div>
    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        <?php if ($this->params['list']): ?>
            <?php foreach ($this->params['list'] as $v): ?>
                <div class="panel panel-<?php echo ['success', 'primary', 'danger', 'info'][rand(0, 3)]; ?>">
                    <div class="panel-heading"><?php echo $v['date']; ?><?php echo $v['name']; ?></div>
                    <div class="panel-body">
                        <?php $product = json_decode($v['product_list'], true); ?>
                        <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2"><img style="width:100px;height:100px"
                                                                              src="<?php echo isset($product[0]['img_src'][0]) ? $product[0]['img_src'][0] : '/statics/img/logo2.png'; ?>"/>
                        </div>
                        <div class="col-lg-1 col-sm-1 col-md-1 col-xs-1"><?php echo $v['pi_id']; ?></div>
                        <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2"><?php $customer = json_decode($v['customer_info'], true);
                            echo $customer['buyer']; ?></div>
                        <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2"><?php echo $v['number']; ?></div>
                        <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
                            <?php
                            foreach ($product as $v2):
                                echo $v2['item'] . "<br/>";
                            endforeach;
                            ?>
                        </div>
                        <div class="btn-group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                    aria-haspopup="true" aria-expanded="false">
                                查看历史版本<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" style="margin-left:25px">
                                <?php foreach ($this->params['oldlist'][$v['pi_id']] as $k2 => $v2) { ?>
                                    <li>
                                        <a href="/sell/pi_edit?id=<?php echo $v2['id']; ?>"><?php echo date('m-d H:i', $v2['create_at']); ?></a>
                                    </li>
                                <?php } ?>
                            </ul>
                        </div>
                        <a href="/sell/pi_edit?id=<?php echo $v['id']; ?>"
                           class="layui-btn layui-btn-normal layui-btn-small">编辑</a>
                        <?php if (!in_array($v['id'], $this->params['pi_arr'])) { ?>
                            <a href="/sell/invoice?id=<?php echo $v['id']; ?>"
                               class="layui-btn layui-btn-warm layui-btn-small">添加Invoice</a>
                        <?php } ?>
                        <a href="/sell/download_pi?id=<?php echo $v['id']; ?>&type=1"
                           class="layui-btn layui-btn-danger layui-btn-small">下载excel</a>
                    </div>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
        <div id="page" style="display:inline-block;"></div>
    </div>

</div>

<script>
    new Vue({
        el: "#main",
        data: {
            staff:<?php echo yii::$app->request->get('staff') ?? 0;?>,
            pi: "<?php echo yii::$app->request->get('pi');?>",
            staff_list:<?php echo json_encode($this->params['staff_list']);?>
        },
        methods: {}
    })
    layui.laypage({
        cont: "page",
        curr:<?php echo $this->params['page']['curr'];?>,
        pages:<?php echo $this->params['page']['page'];?>,
        skin: "#5FB878",
        skip: true,
        jump: function (obj, first) {
            if (!first) {
                if (window.location.search) {
                    window.location.href = "<?php echo $this->params['page']['url'];?>" + "&p=" + obj.curr;
                }
                else {
                    window.location.href = "<?php echo $this->params['page']['url'];?>" + "?p=" + obj.curr;
                }
            }
        }
    })
</script>
<?php echo $this->render('/public/footer'); ?>
